﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class View_ProductDetails :_View_ProductDetails
    {
        public static View_ProductDetails GetProductDetailsByProductID(int productID)
        {
            try
            {
                View_ProductDetails productDetails = new View_ProductDetails();
                productDetails.Where.ProductID.Value = productID;
                productDetails.Where.BranchID.Value = Branches.CurrentBranchID;
                productDetails.Query.Load();

                return productDetails;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_ProductDetails.cs", "GetProductDetailsByProductID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_ProductDetails GetProductDetailsByID(int ID)
        {
            try
            {
                View_ProductDetails productDetails = new View_ProductDetails();
                productDetails.Where.ID.Value = ID;
                productDetails.Query.Load();

                return productDetails;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_ProductDetails.cs", "GetProductDetailsByID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_ProductDetails GetAvailableProductDetailsByIMEI(String imei)
        {
            try
            {
                View_ProductDetails productDetails = new View_ProductDetails();
                productDetails.Where.IMEI.Value = imei;
                productDetails.Where.BranchID.Value = Branches.CurrentBranchID;
                productDetails.Where.ProductStatusID.Value = (int)ProductDetails.ProductStatus.Purchased;
                productDetails.Query.Load();

                return productDetails;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_ProductDetails.cs", "GetProductDetailsByProductID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_ProductDetails GetSaledProductDetailsByIMEI(String imei)
        {
            try
            {
                View_ProductDetails productDetails = new View_ProductDetails();
                productDetails.Where.IMEI.Value = imei;
                productDetails.Where.ProductStatusID.Value = (int)ProductDetails.ProductStatus.Saled;
                productDetails.Where.BranchID.Value = Branches.CurrentBranchID;
                productDetails.Query.Load();

                return productDetails;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_ProductDetails.cs", "GetProductDetailsByProductID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_ProductDetails GetAvailableProductDetailsByProductIDLocationID(int productID, int locationID)
        {
            try
            {
                View_ProductDetails productDetails = new View_ProductDetails();
                productDetails.Where.ProductID.Value = productID;
                productDetails.Where.StockLocationID.Value = locationID;
                productDetails.Where.ProductStatusID.Value = (int)ProductDetails.ProductStatus.Purchased;

                productDetails.Query.Load();

                return productDetails;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_ProductDetails.cs", "GetProductDetailsByProductIDLocationID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_ProductDetails GetAvailableProductDetailsByProductIDLocationID(int productID)
        {
            try
            {
                View_ProductDetails productDetails = new View_ProductDetails();
                productDetails.Where.ProductID.Value = productID;
                productDetails.Where.ProductStatusID.Value = (int)ProductDetails.ProductStatus.Purchased;
                productDetails.Where.BranchID.Value = Branches.CurrentBranchID;
                productDetails.Query.Load();

                return productDetails;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_ProductDetails.cs", "GetProductDetailsByProductIDLocationID", ex.StackTrace);
                throw ex;
            }
        }

    }
}
